package esay.array;

/**
 * 股票交易最大收益
 * @author ruizhou
 * @date 24.2.2018
 */
public class BestTime2BuyAndSellStock_Two {

    public static int maxProfit(int[] prices) {
        int total = 0;
        for (int i = 1, size = prices.length; i < size; i++) {
            if (prices[i] > prices[i-1]) {
                total += prices[i] - prices[i-1];
            }
        }
        return total;
    }

    public static void main(String[] args) {
        int[] prices = {1,2,1,5,7};
        System.out.println(maxProfit(prices));
    }
}
